const fs = require('fs');
const cheerio = require('cheerio');
const axios = require('axios');


// axios.get('https://www.zhihu.com/question/26790346').then(function(rep){
//     // console.log(rep.data.replace('&quot;','/'))
//     var str = rep.data + '';
//     console.log(str.replace("&quot;","/"))
//     const $ = cheerio.load(rep.data + '');
//     var b = $('.List-item').map(function(i, el) {
//         console.log(i)
//     // console.log(b)
//     })
// }).catch(function(err){
//     console.log(err)
// })
var arr = [];
var url = "http://36kr.com/p/"
function getPage(i) {
    var a = url + i + '.html'
    console.log(a)
    axios.get(url+i+'.html').then(function(rep){
        // console.log(rep.data)
        const $ = cheerio.load(rep.data + '');
        console.log($('.header-pop-message.J_sendPostWin').html(), 121212121)
        var jsonData = {
            "title": $('.mobile_article').text(),
            "name": $('.name').text(),
            "summary": $('.summary').text()
        }
        //  getPage(++i)
        fs.writeFile('message.txt', JSON.stringify(jsonData), (err) => {
            if (err) throw err;
            console.log('The file has been saved!');
        });
       
    }).catch(function(err){
        // console.log(err.response, '21321')
        getPage(i+1)
    })
}
getPage(1)